package acwing;

import java.io.*;
//二进制优化
public class A5 {
    static int n;
    static int m;
    static int N=12010;
    static int M=2010;
    static int[] v=new int[N];
    static int[] w=new int[N];

    static int[]dp=new int[N];
    static BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter log=new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] t = read.readLine().split(" ");
        n=Integer.parseInt(t[0]);
        m=Integer.parseInt(t[1]);
        int cnt=0;//分组的组别
        for(int i=1;i<=n;i++){
            String[] s1 = read.readLine().split(" ");
            int a=Integer.parseInt(s1[0]);//体积
            int b=Integer.parseInt(s1[1]);//价值
            int s=Integer.parseInt(s1[2]);
            int k=1;//组别里面的个数
            while(k<=s){
                cnt++;//先把组别加上
                v[cnt]=k*a;
                w[cnt]=k*b;
                s-=k;
                k*=2;
            }
            if(s>0){
                cnt++;
                v[cnt]=s*a;
                w[cnt]=s*b;
            }

        }
        n=cnt;//n正式由物品种类变为组别
        //把一个组看成一个物品
        for(int i=1;i<=n;i++){//枚举第i个组别的决策
            for(int j=m;j>=v[i];j--) {
                dp[j] = Math.max(dp[j], dp[j-v[i]]+w[i]);
            }
        }
        log.write(Integer.toString(dp[m]));
        log.flush();
    }
}
